package com.cskaoyan.servlet;


import com.cskaoyan.bean.common.BaseRespVo;
import com.cskaoyan.bean.common.CommonData;
import com.cskaoyan.service.GroupGoodsManagementService;
import com.cskaoyan.service.GroupGoodsManagementServiceImpl;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;

@WebServlet("/admin/goods/list")
public class GroupGoodsManagementListServlet extends WdBaseServlet{

    GroupGoodsManagementService groupGoodsManagementService = new GroupGoodsManagementServiceImpl();

    public BaseRespVo list(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException {
        Integer page = Integer.parseInt(request.getParameter("page"));
        Integer limit = Integer.parseInt(request.getParameter("limit"));
        String order = request.getParameter("order");
        String sort = request.getParameter("sort");
        String goodsId = null;
        String goodsSn = null;
        String name = null;

        String param = request.getParameter("name");
        if (param != null) {
            name = URLDecoder.decode(param, "UTF-8");
        }

        goodsId = request.getParameter("goodsId");
        if(goodsId == null) {
            goodsId = "";     // 提供默认值
        }

        goodsSn = request.getParameter("goodsSn");
        if(goodsSn == null) {
            goodsSn = "";
        }

        name = request.getParameter("name");
        if(name == null) {
            name = "";
        }

        CommonData data = groupGoodsManagementService.groupGoodsQuery(page,limit,sort,order,goodsId,goodsSn,name);
        return BaseRespVo.ok(data);//会转换为json字符，然后通过 response的getWriter去响应
    }
}
